home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDStatus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  3.8 KB  |  145 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDStatus - An XFCN to return CDROM status
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDStatus.c
  11.     link -sn Main=CDStatus -sn STDIO=CDStatus ∂
  12.          -sn INTENV=CDStatus -rt XFCN=42 ∂
  13.          -m CDStatus CDStatus.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. OSErr    AStatus(short, short *);
  28.  
  29. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  30.  
  31.  
  32. /************************************************************************
  33.  *
  34.  *  Function:        CDStatus
  35.  *
  36.  *  Purpose:        return cd audio status
  37.  *
  38.  *  Returns:        a status value, or a negative error value.
  39.  *                    0 = audio pause in progress
  40.  *                    1 = audio play in progress
  41.  *                    2 = audio muting on
  42.  *                    3 = audio play operation completed
  43.  *                    4 = error occurred during audio play
  44.  *                    5 = not currently playing
  45.  *
  46.  *                    -1 = incorrect number of parameters
  47.  *                    other errors are from the driver. See the
  48.  *                    developer's guide for more details.
  49.  *
  50.  *  Side Effects:
  51.  *
  52.  *  Description:    We need no parameter.  Get the ioRefNum from the
  53.  *                    famous global set by CDOpen().  Call the driver to get
  54.  *                    status, and return it.
  55.  *
  56.  *                    If the status is 0, return 1.  If the status is 1,
  57.  *                    return 0. This makes for a convenient consistent
  58.  *                    interface for the user (0 always means pause).
  59.  *
  60.  ************************************************************************/
  61. pascal void
  62. CDStatus(paramPtr)
  63. XCmdBlockPtr    paramPtr;
  64. {
  65.     Str31    returnString;
  66.     OSErr    result;
  67.     short    status;
  68.     short    ioRefNum;
  69.     Handle    refHandle;
  70.     
  71.     /* Must be only no parameter */
  72.     if ((paramPtr->paramCount) != 0)
  73.     {
  74.         /* Report error in parameters by returning -1 */
  75.         NumToStr(paramPtr, (long) -1, &returnString);
  76.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  77.         return;
  78.     }
  79.     
  80.     /* Get the global ioRefNum and convert it. */
  81.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  82.     ioRefNum = atoi(*(refHandle));
  83.     DisposHandle(refHandle);
  84.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  85.     
  86.     result = AStatus(ioRefNum, &status);
  87.     
  88.     if (result == noErr)
  89.     {
  90.         if (status == 1)        /* for consistency. pause is always reported as 0 */
  91.             status = 0;
  92.         else if (status == 0)
  93.             status = 1;
  94.         /* Convert status to string & return it */
  95.         NumToStr(paramPtr, (long) status, &returnString);
  96.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  97.     }
  98.     else
  99.     {
  100.         /* Convert result to string & return it as error */
  101.         NumToStr(paramPtr, (long) result, &returnString);
  102.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  103.     }
  104. }
  105.  
  106. /************************************************************************
  107.  *
  108.  *  Function:        AStatus
  109.  *
  110.  *  Purpose:        return CD audio status
  111.  *
  112.  *  Returns:        OSErr.  Probably either
  113.  *                        noErr        everything's hunky-dory!
  114.  *                        paramErr    you messed up the call somehow.
  115.  *
  116.  *  Side Effects:    modifies "status" to reflect the audio status byte
  117.  *                    returned by the driver.
  118.  *
  119.  *  Description:    Simply call the driver and return the audio status
  120.  *                    byte that the driver gives us.
  121.  *
  122.  ************************************************************************/
  123. OSErr
  124. AStatus(refNum, status)
  125. short    refNum;
  126. short    *status;
  127. {
  128.     CDStatusParam    myPB;
  129.     OSErr    result;
  130.     
  131.     myPB.ioCompletion = 0;
  132.     myPB.ioNamePtr = (char *) 0;
  133.     myPB.ioVRefNum = 1;
  134.     myPB.ioCRefNum = refNum;
  135.     myPB.csCode = ASTATUS;
  136.     
  137.     result = PBControl(&myPB, false);
  138.     *status = (short) myPB.audioStatus;
  139.     return result;
  140. }
  141.  
  142.  
  143. /* C routines for HyperCard callbacks */
  144. #include <XCmdGlue.inc.c>
  145.